import axios from 'axios'
import router from '../router'
import { Message } from 'element-ui'
let instence = axios.create()
instence.defaults.timeout = 5000
// let loadinginstace
instence.interceptors.request.use(config => {
  // loadinginstace = Loading.service({ fullscreen: true })
  config.headers['access-token'] = localStorage.getItem('token') || ''
  return config
}, error => {
  // loadinginstace.close()
  Message.error('加载超时')
  return Promise.reject(error)
})
instence.interceptors.response.use(data => {
  // loadinginstace.close()
  if (data.status === 200) {
    if (data.data.code === 100) {
      Message.error('请重新登录')
      router.push('/login')
    }
    return data
  }
}, error => {
  // loadinginstace.close()
  return Promise.reject(error)
})
export default instence
